package com.esun.cheetah.view.odds.adapter;

import java.util.ArrayList;
import java.util.Hashtable;

import com.esun.cheetah.R;


import com.esun.cheetah.view.personal.sportlotteryfootballinfo.SportteryFootballAgainstInfo;
import com.esun.util.log.EDebug;


import android.content.Context;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;

import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;


public class SportteryFootballExpandableListAdapter extends BaseExpandableListAdapter{
	private LayoutInflater listInflater;
	private ArrayList<ArrayList<Hashtable<String, Object>>> listChild = new ArrayList<ArrayList<Hashtable<String, Object>>>();
	private ArrayList<Hashtable<String, Object>> listGroup = new ArrayList<Hashtable<String, Object>>();

	public SportteryFootballExpandableListAdapter(Context context) {
		this.listInflater = LayoutInflater.from(context);
	}

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		return listChild.get(groupPosition).get(childPosition);
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		return childPosition;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) {
		if (convertView == null) {
			EDebug.o( "新建view "
					+ childPosition);
			convertView = (RelativeLayout) listInflater.inflate(
					R.layout.odds_eru_item, null);
		}
		final SportteryFootballAgainstInfo sportteryFootballAgainstInfo = (SportteryFootballAgainstInfo) listChild
				.get(groupPosition).get(childPosition).get("info");
		((TextView) convertView
				.findViewById(R.id.sportteryfootballchooseitem_tv_homeName))
				.setText(sportteryFootballAgainstInfo.getHomesxname());
		((TextView) convertView
				.findViewById(R.id.sportteryfootballchooseitem_tv_visiterName))
				.setText(sportteryFootballAgainstInfo.getAwaysxname());
		((TextView) convertView
				.findViewById(R.id.sportteryfootballchooseitem_tv_leagueName))
				.setText(sportteryFootballAgainstInfo.getSimpleleague());
		((TextView) convertView
				.findViewById(R.id.sportteryfootballchooseitem_tv_rangqiu))
				.setText(sportteryFootballAgainstInfo.getRangqiu());
		String strPtggEndTime = sportteryFootballAgainstInfo.getEndtime()
				.substring(10, 16);
		// String strPtggEndTime = "1123";

		((TextView) convertView
				.findViewById(R.id.tv_match_list_score_item_host_team_number))
				.setText(sportteryFootballAgainstInfo.getHomestanding());
		((TextView) convertView
				.findViewById(R.id.tv_match_list_score_item_guest_team_number))
				.setText(sportteryFootballAgainstInfo.getAwaystanding());

		((TextView) convertView
				.findViewById(R.id.sportteryfootballchooseitem_tv_ptggEndTime))
				.setText(strPtggEndTime);

		((TextView) convertView
				.findViewById(R.id.sportteryfootballchooseitem_cbx_WT))
				.setText(sportteryFootballAgainstInfo.getWin().toString());
		((TextView) convertView
				.findViewById(R.id.sportteryfootballchooseitem_cbx_DT))
				.setText(sportteryFootballAgainstInfo.getDraw().toString());
		((TextView) convertView
				.findViewById(R.id.sportteryfootballchooseitem_cbx_LT))
				.setText(sportteryFootballAgainstInfo.getLost().toString());

		
		// + sportteryFootballAgainstInfo.getLost());
		EDebug.o("sportteryFootballAgainstInfo.getWin()--- "
				+ sportteryFootballAgainstInfo.getWin());

		return convertView;
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		return listChild.get(groupPosition).size();
	}

	@Override
	public Object getGroup(int groupPosition) {
		return listGroup.get(groupPosition);
	}

	@Override
	public int getGroupCount() {

		return listGroup.size();
	}

	@Override
	public long getGroupId(int groupPosition) {
		return groupPosition;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded,
			View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = (LinearLayout) listInflater.inflate(
					R.layout.odds_eur_item_title, null);
		}
		((TextView) convertView
				.findViewById(R.id.sportteryfootballchooseact_tv_date))
				.setText((String) listGroup.get(groupPosition).get("date"));
		((TextView) convertView
				.findViewById(R.id.sportteryfootballchooseact_tv_day))
				.setText((String) listGroup.get(groupPosition).get(
						"day_of_week"));
		((TextView) convertView
				.findViewById(R.id.sportteryfootballchooseact_tv_mtachCount))
				.setText(Integer.toString((Integer) listGroup.get(
						groupPosition).get("item_count")));
		ImageView imgExpand = (ImageView) convertView
				.findViewById(R.id.sportteryfootballchooseact_img_expand);
		if (isExpanded) {
			imgExpand.setBackgroundResource(R.drawable.icon_default_packup);
		} else {
			imgExpand.setBackgroundResource(R.drawable.icon_default_unfold);
		}
		return convertView;
	}

	@Override
	public boolean hasStableIds() {
		return false;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {

		return true;
	}

	@Override
	public boolean areAllItemsEnabled() {
		return true;
	}

	public void hideGroup(int groupPos) {

	}
}